package com.woniu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.mapper.UserMapper;
import com.woniu.pojo.User;
import com.woniu.service.IUserService;
import org.mockito.internal.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.servlet.annotation.WebFilter;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService{

    @Autowired
    private UserMapper userMapper;
//分页查询
    @Override
    public IPage<User> listpage(Integer currentPage, Integer pageSize, String name) {
        IPage page = new Page(currentPage,pageSize);
        QueryWrapper<User> wrapper = new QueryWrapper();
        if (!StringUtils.isEmpty(name) && name.length()>0){
            wrapper.like("name",name);
        }

        IPage page1 = userMapper.selectPage(page, wrapper);

        return page1;
    }

//    删除
    @Override
    public Integer deleteuser(Integer id) {
//       根据传入id直接删除
        Integer i = userMapper.deleteById(id);

//        根据wapper条件删除
        QueryWrapper<User> wrapper = new QueryWrapper();
        wrapper.eq("id",id);
        userMapper.delete(wrapper);

//        根据实体类属性删除
        User user = new User();
        user.setId(id);
        userMapper.deleteById(user);

     return i;
    }
//新增
    @Override
    public Integer saveuser(User user) {
        int i = userMapper.insert(user);
        return i;
    }

    @Override
    public Integer updateuser(User user) {
//        根据所传入的实体类修改
        Integer i = userMapper.updateById(user);
//        根据传入的实体类，和传入的属性值修改
        QueryWrapper<User> wrapper = new QueryWrapper();
        Integer update = userMapper.update(user, wrapper);
         return update;
    }

//

}
